package com.cyou.dream.runner;

import com.cyou.dream.core.IRiskEngine;
import com.cyou.dream.logging.LogMarkers;
import com.cyou.dream.util.SystemUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Log4j2
@Component
public class CheckRiskConfigRunner implements ApplicationRunner {

    private final IRiskEngine riskEngine;

    public CheckRiskConfigRunner(IRiskEngine riskEngine) {
        this.riskEngine = riskEngine;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        boolean checkConfigResult = riskEngine.checkRiskConfig(riskEngine.getCurrentConfig().getStrategies());
        if(!checkConfigResult) {
            log.error(LogMarkers.DreamRiskEngine, "Exit from CheckRiskConfigRunner: config not illegal");
            System.exit(SystemUtil.EXIT_RISK_ENGINE_CONFIG_ERROR);
        }
    }
}
